import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus' //全局引入
import 'element-plus/dist/index.css'
import axios from "axios";
createApp(App).use(router).use(ElementPlus).mount('#app')




axios.interceptors.request.use(config => {
    // 1.从缓存中获取到token,这里的Authorization时登录时你给用户设置token的键值
    let authorization = localStorage.getItem("token");
    console.log(authorization+"我的")
    config.withCredentials=true;
    config.headers["Content-Type"]="application/json";
    // 2.如果token不为null，那么设置到请求头中，此处哪怕为null，我们也不进行处理，因为后台会进行拦截
    if (authorization) {
        //后台给登录用户设置的token的键时什么，headers['''']里的键也应该保持一致
        config.headers['token'] = authorization;
    }
    // 3.放行
    return config;
}, error => {
//失败后抛出错误
    Promise.reject(error);
})
